using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;

public class CubeObj : MonoBehaviour
{
    public GameObject[] rewards;

    public GameObject destroyEffect;

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
    }

    private void OnTriggerEnter(Collider other)
    {
        BulletObj bulletObj = other.GetComponent<BulletObj>();
        if (bulletObj != null && bulletObj.own.tag.Equals("Player"))
        {
            //打到箱子 随机出奖励
            int range = Random.Range(0, 100);
            if (range < 50)
            {
                int index = Random.Range(0, rewards.Length);
                GameObject reward = Instantiate(rewards[index], this.transform.position, this.transform.rotation);
                reward.transform.eulerAngles = new Vector3(-45, 0, 0);
            }

            GameObject effect = Instantiate(destroyEffect, this.transform.position, this.transform.rotation);
            AudioSource audioSource = effect.GetComponent<AudioSource>();
            audioSource.volume = GameDataManager.Instance.musicData.soundValue;
            audioSource.mute = !GameDataManager.Instance.musicData.isOpenSound;
            Destroy(this.gameObject);
            
        }
    }
}